home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Language.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  4.7 KB  |  210 lines

  1. /* 
  2.  *  language.cpp 
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23. #include <windows.h>
  24. #include <winbase.h>
  25.  
  26. #define LANGUAGE_MODULE
  27. #include "Language.h"
  28. #undef  LANGUAGE_MODULE
  29.  
  30. //////////////////////////////////////////////////////////////////////
  31. // Construction/Destruction
  32. //////////////////////////////////////////////////////////////////////
  33. static char filenames[MAX_LANGUAGES][1024];
  34. static char * strings[MAX_LANGUAGES][MAX_STRINGS];
  35. static int    strings_alloc[MAX_LANGUAGES][MAX_STRINGS];
  36.  
  37.  
  38. CLanguage::CLanguage()
  39. {
  40.     selected_language=0;
  41. }
  42.  
  43. CLanguage::~CLanguage()
  44. {
  45.     int i,j;
  46.     //Deallocate strings
  47.     for(i=0; i<MAX_LANGUAGES; i++)
  48.         for(j=0; j<MAX_STRINGS; j++){                  
  49.             if(strings_alloc[i][j] == 1)
  50.                 free(strings[i][j]);
  51.         }
  52.  
  53. }
  54.  
  55. int CLanguage::Start()
  56.  
  57. {
  58.     WIN32_FIND_DATA find_data;
  59.     char     directory[MAX_PATH];
  60.     char     mask[MAX_PATH];
  61.     HANDLE   search_handle;
  62.     int      no_lang_package_flag;
  63.     int i,j;
  64.  
  65.     GetCurrentDirectory(MAX_PATH, directory);    
  66.     strcat(directory,"\\Lang\\*.lang.flask" );
  67.  
  68.     i=0;
  69.     search_handle = FindFirstFile(directory, &find_data);
  70.     if(search_handle==INVALID_HANDLE_VALUE){
  71.         n_lang=0;
  72.     }
  73.     else{
  74.         strcpy( filenames[i++], find_data.cFileName );
  75.         while( FindNextFile(search_handle, &find_data ) ){
  76.             strcpy( filenames[i++], find_data.cFileName );
  77.         }
  78.         FindClose(search_handle);
  79.         n_lang = i;
  80.     }
  81.     if(n_lang==0)
  82.         n_lang=1;
  83.  
  84.     no_lang_package_flag = !n_lang;
  85.  
  86.     //initialize string pointers
  87.     for(i=0; i<MAX_LANGUAGES; i++)
  88.         for(j=0; j<MAX_STRINGS; j++){
  89.                   strings[i][j] = NULL;
  90.             strings_alloc[i][j] = 0;
  91.         }
  92.  
  93.  
  94.  
  95.     LoadDefaultStrings();
  96.     // load default strings in all language sets
  97.     for(i=0; i<n_lang; i++)
  98.         for(j=0; j<MAX_STRINGS; j++)
  99.             strings[i][j] = ds[j] ? ds[j]:NULL;
  100.  
  101.     //Load strings from files
  102.     if(!no_lang_package_flag){
  103.         for(i=0;i<n_lang;i++)
  104.             ReadLanguage(i);
  105.     }
  106.     selected_language=0;
  107.     return 0;
  108. }
  109.  
  110. int CLanguage::GetNumberLang()
  111. {
  112.     return n_lang;
  113. }
  114.  
  115. char * CLanguage::GetLanguageID()
  116. {
  117.     char *ID;
  118.     ID=strings[selected_language][0];
  119.     if(ID)
  120.         return ID;
  121.     else
  122.         return "unknown";
  123. }
  124. int CLanguage::GetLanguage()
  125. {
  126.     return selected_language;
  127. }
  128.  
  129. int CLanguage::SetLanguage(int n_lang)
  130. {
  131.     if(n_lang >= this->n_lang)
  132.         return 0;
  133.     selected_language = n_lang;
  134.     return 1;
  135. }
  136.  
  137. char * CLanguage::GetString(int str_id)
  138. {
  139.     if(str_id>MAX_STRINGS)
  140.         return "";
  141.  
  142.     return strings[selected_language][str_id]?strings[selected_language][str_id]:"";
  143. }
  144.  
  145. int CLanguage::GetStrings(FILE *file)
  146. {
  147.     return 0;
  148. }
  149.  
  150. int CLanguage::ReadLanguage(int language)
  151. {
  152.     FILE *f=NULL;
  153.     char  token=0;
  154.     int   str_num, string_chars;
  155.     char  full_name[MAX_PATH];
  156.  
  157.     GetCurrentDirectory(MAX_PATH, full_name);    
  158.     strcat(full_name,"\\Lang\\" );
  159.     strcat(full_name,filenames[language]);
  160.  
  161.     //open file
  162.     f=fopen(full_name, "rb");
  163.     if(!f)
  164.         return 0;
  165.  
  166.     while(!feof(f)){
  167.         //Search for token #
  168.         while(token!='#' && !feof(f))
  169.             fread(&token, 1, 1, f);
  170.         //get number after token
  171.         if(!feof(f)){
  172.             fscanf(f, "%d", &str_num);
  173.             if(str_num>MAX_STRINGS)
  174.                 continue;
  175.         }
  176.  
  177.         //Search for token $
  178.         while(token!='#' && !feof(f))
  179.             fread(&token, 1, 1, f);
  180.         while(token!='"' && !feof(f))
  181.             fread(&token, 1, 1, f);
  182.  
  183.         //Read every single byte of the string
  184.         if(!feof(f)){
  185.             fread(&token, 1, 1, f);
  186.             string_chars = 0;
  187.  
  188.             strings[language][str_num]=NULL;
  189.             while(token!='"' && !feof(f)){
  190.                 string_chars++;
  191.                 strings[language][str_num]=(char *)realloc(strings[language][str_num], string_chars);
  192.                 strings[language][str_num][string_chars - 1] = token;
  193.                 strings_alloc[language][str_num] = 1;
  194.                 fread(&token, 1, 1, f);
  195.             }
  196.             //NULL terminate the string
  197.             string_chars++;
  198.             strings[language][str_num]=(char *)realloc(strings[language][str_num], string_chars);
  199.             strings[language][str_num][string_chars - 1] = 0;
  200.  
  201.         }
  202.  
  203.  
  204.     }
  205.  
  206.     
  207.     fclose(f);
  208.     return 1;
  209. }
  210.